home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / 06_02.iso / software / celestia / files / celestia-win32-1.2.3.exe / {app} / shaders / specular.vp < prev   
Encoding:
Text File  |  2001-09-26  |  1.8 KB  |  67 lines

  1. !!VP1.0
  2.  
  3. # Compute specular and diffuse light from a single source
  4.  
  5. # c[0]..c[3] contains the concatenation of the modelview and projection matrices.
  6. # c[4]..c[7] contains the inverse transpose of the modelview
  7. # c[15] contains the eye position in object space
  8. # c[16] contains the light direction in object space
  9. # c[17] contains H, the normalized sum of the eye and light direction
  10. # c[20] contains the object color * light color
  11. # c[32] contains the ambient light color
  12. # c[33] contains the haze color
  13. # c[34] contains the specular color * light color
  14. # c[40] contains (0, 1, 0, specPower)
  15. # v[OPOS] contains the per-vertex position
  16. # v[NRML] contains the per-vertex normal
  17. # v[TEX0] contains the per-vertex texture coordinate 0
  18. # o[HPOS] output register for homogeneous position
  19. # o[TEX0] output register for texture coordinate 0
  20. # o[COL0] output register for primary color
  21. # R0...R11 temporary registers
  22.  
  23. # Transform the vertex by the modelview matrix
  24. DP4   R1.x, c[0], v[OPOS];
  25. DP4   R1.y, c[1], v[OPOS];
  26. DP4   R1.z, c[2], v[OPOS];
  27. DP4   R1.w, c[3], v[OPOS];
  28.  
  29. # Compute the diffuse light component
  30. DP3   R2, v[NRML], c[16];
  31. # Clamp the diffuse component to zero
  32. MAX   R2.x, R2, c[40].xxxx;
  33.  
  34. # Get the vector from the eye to the vertex
  35. ADD   R4, c[15], -v[OPOS];
  36.  
  37. # Normalize it
  38. DP3   R0.w, R4, R4;
  39. RSQ   R0.w, R0.w;
  40. MUL   R4.xyz, R4, R0.w;
  41.  
  42. # Haze
  43. DP3   R2.y, v[NRML], R4;
  44. ADD   R2.y, c[40].y, -R2.y;
  45. MUL   o[FOGC].x, R2.x, R2.y;
  46.  
  47. # Calculate the specular reflection
  48. MOV   R6.x, R2.x;
  49. DP3   R6.y, c[17], v[NRML];
  50. MAX   R6.y, R6, c[40].x;
  51. MOV   R6.w, c[40].w;
  52.  
  53. # Output the texture
  54. MOV   o[TEX0], v[TEX0];
  55. # Output the primary color
  56. MOV   R0, c[32];
  57. MAD   o[COL0], c[20], R2.xxxx, R0;
  58.  
  59. # Compute and output the secondary color
  60. LIT   R0, R6;
  61. MUL   o[COL1], c[34], R0.zzzz;
  62. # Output the vertex
  63. MOV   o[HPOS], R1;
  64.  
  65. END
  66.  
  67.